<?php

class Admin_Models_Article extends Fengqiaoju_Db_Table {
	
	/**
	 * 文章内容表
	 */
	private $_table_content = "site_article_content";

	public function __construct() {

		parent::__construct ();
		$this->_name = $this->_prefix . "site_article";
		$this->_primary = "article_id";
		$this->_table_content = $this->_prefix . $this->_table_content;
	}

	/**
	 * 文章列表
	 */
	public function getArticleList($where , $order = '' , $count = '' , $offset = '') {

		$where = $this->arrayToString ( $where );
		return $this->fetchAll ( $where, $order, $count, $offset );
	}

	/**
	 * 获取文章信息
	 */
	public function getArticleInfo($where) {

		$where = $this->arrayToString ( $where );
		$article = $this->fetchRow ( $where )->toArray ();
		
		//获取文章内容
		$sql = "select * from {$this->_table_content} WHERE article_id='{$article['article_id']}' ";
		$content = $this->_db->fetchRow ( $sql );
		$article ['article_content'] = $content ['article_content'];
		
		return $article;
	}

	/**
	 * 插入文章
	 */
	public function addArticle($data) {

		$article ['article_title'] = $data ['article_title'];
		$article ['model_id'] = $data ['model_id'];
		$article ['site_id'] = $data ['site_id'];
		$article ['site_seo_name'] = $data ['site_seo_name'];
		$article ['article_updatetime'] = $article ['article_inputtime'] = date ( 'Y-m-d H:i:s' );
		$article_id = $this->insert ( $article );
		$content ['article_content'] = $data ['article_content'];
		$content ['article_id'] = $article_id;
		return $this->_db->insert ( $this->_table_content, $content );
	}

	//编辑文章
	public function updateArticle($data , $where) {

		$where = $this->arrayToString ( $where );
		$article ['article_title'] = $data ['article_title'];
		$article ['article_updatetime'] = date ( 'Y-m-d H:i:s' );
		$article_id = $this->update ( $article, $where );
		$content ['article_content'] = $data ['article_content'];
		return $this->_db->update ( $this->_table_content, $content, $where );
	}
}
?>